package com.kzw.oa.model.system;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

/**
 * 部门与组织的区别： 部门(Department)与组织(Organization)共用同一张表
 */
public class Department implements Serializable {

	private static final long serialVersionUID = 1L;
	/** 集团 */
	public final static Short ORG_TYPE_GROUP = 0;
	/** 公司 */
	public final static Short ORG_TYPE_COMPANY = 1;
	/** 部门 */
	public final static Short ORG_TYPE_DEPARTMENT = 2;

	protected Long depId;
	protected String depName;
	protected String depDesc;
	protected Integer depth;
	protected Long parentId;
	protected String path;
	protected Short orgType;

	protected Long creatorId;
	protected Date createtime;
	protected Long updateId;
	protected Date updatetime;
	protected Integer sn;

	protected Set<AppUser> appUsers = new HashSet<>();
	protected Set<UserOrg> userOrgs = new HashSet<>();
	protected String chargeIds;
	protected String chargeNames;

	// 简称
	private String shortName;
	// 全称
	private String fullName;
	// 代码
	private String code;
	// 是否删除
	private Short delFlag = 0;

	public Department() {

	}

	public Department(Long depId) {
		this.setDepId(depId);
	}

	public Long getDepId() {
		return depId;
	}

	public void setDepId(Long depId) {
		this.depId = depId;
	}

	public String getDepName() {
		return depName;
	}

	public void setDepName(String depName) {
		this.depName = depName;
	}

	public String getDepDesc() {
		return depDesc;
	}

	public void setDepDesc(String depDesc) {
		this.depDesc = depDesc;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getChargeIds() {
		chargeIds = "";
		Set<UserOrg> uos = getUserOrgs();
		for (UserOrg uo : uos) {
			if (uo.isCharge != null && uo.isCharge == 1) {
				chargeIds += uo.userOrgId + ",";
			}
		}
		if (chargeIds.length() > 0) {
			chargeIds = chargeIds.substring(0, chargeIds.length() - 1);
		}
		return chargeIds;
	}

	public void setChargeIds(String chargeIds) {
		this.chargeIds = chargeIds;
	}

	public String getChargeNames() {
		chargeNames = "";
		Set<UserOrg> uos = getUserOrgs();
		for (UserOrg uo : uos) {
			if (uo.isCharge != null && uo.isCharge == 1) {
				AppUser au = uo.appUser;
				chargeNames += au.getFullname() + ",";
			}
		}
		if (chargeNames.length() > 0) {
			chargeNames = chargeNames.substring(0, chargeNames.length() - 1);
		}
		return chargeNames;
	}

	public void setChargeNames(String chargeNames) {
		this.chargeNames = chargeNames;
	}

	public Short getOrgType() {
		return orgType;
	}

	public void setOrgType(Short orgType) {
		this.orgType = orgType;
	}

	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public Long getUpdateId() {
		return updateId;
	}

	public void setUpdateId(Long updateId) {
		this.updateId = updateId;
	}

	public Date getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(Date updatetime) {
		this.updatetime = updatetime;
	}

	public Long getCreatorId() {
		return creatorId;
	}

	public void setCreatorId(Long creatorId) {
		this.creatorId = creatorId;
	}

	public Set<AppUser> getAppUsers() {
		return appUsers;
	}

	public void setAppUsers(Set<AppUser> in_appUsers) {
		this.appUsers = in_appUsers;
	}

	public Set<UserOrg> getUserOrgs() {
		return userOrgs;
	}

	public void setUserOrgs(Set<UserOrg> in_userOrgs) {
		this.userOrgs = in_userOrgs;
	}

	public Integer getSn() {
		return sn;
	}

	public void setSn(Integer sn) {
		this.sn = sn;
	}

	public String getShortName() {
		if (StringUtils.isNotBlank(shortName)) {
			return shortName;
		}
		return depName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getDepth() {
		return depth;
	}

	public void setDepth(Integer depth) {
		this.depth = depth;
	}

	public Short getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(Short delFlag) {
		this.delFlag = delFlag;
	}

}
